package com.antbee.cms.ruili.spring.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.antbee.cms.ruili.hibernate.model.ToolLengths;
import com.antbee.cms.ruili.spring.dao.ToolDAO;

public class ToolDAOImpl extends HibernateDaoSupport implements ToolDAO {

	public List GetToolInfo(String Manuname) {
		String sql = "from ToolInfo as a where a.manuName= :ManuName";
		Query query = this.getSession().createQuery(sql);
		query.setString("ManuName", Manuname);// 5
		return query.list();
	}

	public List GetToolInfoAll() {
		List Lsql = this.getHibernateTemplate().find("from ToolInfo as a where a.linkSpecFix is null");
		return Lsql;
	}
	public List GetToolInfoEcho() {
		List Lsql = this.getHibernateTemplate().find("from ToolInfo as a where a.linkSpecFix is not null");
		return Lsql;
	}

	public List GetToolLength(String LayerNo) {
		List Lsql = this.getHibernateTemplate().find("from ToolLengths as a where a.layerNo="+LayerNo+" order by a.orderNo");
		return Lsql;
	}

	public List FirstProduct(String Type) {
		List Lsql = this.getHibernateTemplate().find("from ToolInfo as a where a.tuiJian="+Type+"  and length(a.productName)<25 order by a.id");
		if (Lsql.size()>9){
			Lsql = Lsql.subList(0, 8);
		}
		return Lsql;
	}

	public List NewTechInfo(String Type) {
		List Lsql = this.getHibernateTemplate().find("from Techdatum as a where a.orderNo="+Type+" order by a.operDate desc");
		if (Lsql.size()>5){
			Lsql = Lsql.subList(0, 4);
		}
		return Lsql;
	}

	public List GetChildList(String ParentId) {
		List Lsql = this.getHibernateTemplate().find("from ToolLengths as a where a.parentId="+ParentId);
		return Lsql;
	}

	public List GetChildListByManu(String Manuname) {
		String sql = "from ToolLengths as a where a.sonName= :ManuName";
		Query query = this.getSession().createQuery(sql);
		query.setString("ManuName", Manuname);// 5
		if (query.list().size()>0){
			ToolLengths len = (ToolLengths) query.list().get(0);
			return this.GetChildList(len.getId().toString());
		}
		return null;
	}
	
	public List GetToolInfoXL(String Productid) {		
		return this.getHibernateTemplate().find("from ToolInfo as a where a.toolLengths.id="+Productid);
	}

	public List GetSameXl(String ProductId) {
		return this.getHibernateTemplate().find("from ToolLengths as a where a.parentId="+ProductId);		
	}

	public List GetLikeProInfo(String ProductSpec) {		
		String sql = "from ToolInfo as a where a.productSpec=:Productspec and a.linkSpecFix != null";
		Query query = this.getSession().createQuery(sql);
		query.setString("Productspec", ProductSpec);// 5
		return query.list();
	}
	public List GetLikeProEcho(String Pid,String ProductSpec) {		
		String sql = "from ToolInfo as a where a.productSpec=:Productspec and a.id != :Pid";
		Query query = this.getSession().createQuery(sql);
		query.setString("Productspec", ProductSpec);// 5
		query.setString("Pid", Pid);// 5
		return query.list();
	}

}
